package com.dify.knowledge.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dify.knowledge.entity.Document;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 文档Mapper接口
 */
@Mapper
public interface DocumentMapper extends BaseMapper<Document> {
    
    /**
     * 分页查询所有文档
     * @param page 分页对象
     * @return 分页结果
     */
    @Select("SELECT * FROM document ORDER BY created_at DESC")
    Page<Document> selectAllDocuments(Page<Document> page);
    
    /**
     * 根据文件名查询文档
     * @param fileName 文件名
     * @return 文档对象
     */
    @Select("SELECT * FROM document WHERE file_name = #{fileName} LIMIT 1")
    Document selectByFileName(@Param("fileName") String fileName);
}
